package cn.life.common.support.datasource;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;



@Aspect
@Order(-100)
@Component
public class DataSourceAop {

    @Before("@annotation(cn.life.common.support.datasource.DataSource) && @annotation(dataSource)")
    public void convert(JoinPoint joinPoint, DataSource dataSource) {
        DataSourceContextHolder.setDataSource(dataSource.value());
    }

    @After("@annotation(cn.life.common.support.datasource.DataSource)")
    public void after(JoinPoint point) {
        DataSourceContextHolder.clear();
    }

}
